﻿@{
    Layout = "~/Views/Shared/_FormWhite.cshtml";
}

<div class="wrapper animated fadeInRight">
    <form id="form" class="form-horizontal m">
        <div class="form-group">
            <label class="col-sm-3 control-label ">管理员</label>
            <div class="col-sm-8">
                <div id="userId" col="userId"></div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">小程序模块权限<font class="red"> *</font></label>
            <div class="col-sm-8">
                 <div id="moduleTree" class="ztree"></div>
            </div>
        </div>
    </form>
</div>

<script type="text/javascript">
    var id = ys.request("id");
    var moduleIds=ys.request("moduleIds");
    $(function () {

        $("#userId").ysComboBox({
            url: '@Url.Content("~/OrganizationManage/User/GetHYListJson")',
            key: "Id",
            value: "UserName",
            class: "form-control"
        });

        $('#moduleTree').ysTree({
            async: false,
            url: '@Url.Content("~/QixingManage/ModuleCategory/GetModuleCategoryTreeListJson")',
            check: { enable: true },
            expandLevel: 0
        })

        getForm();

        $('#form').validate({
            rules: {
                module_category_Id: { required: true }
            }
        });
    });

    function getForm() {
        if (id > 0) {
            var obj = {};
            obj.userId = id;
            $('#moduleTree').ysTree("setCheckedNodes",moduleIds);
            $('#form').setWebControls(obj);
            //ys.ajax({
            //    url: '@Url.Content("~/QixingManage/ModuleCategoryUser/GetFormJson")' + '?id=' + id,
            //    type: 'get',
            //    success: function (obj) {
            //        if (obj.Tag == 1) {
            //            $('#form').setWebControls(obj.Data);
            //        }
            //    }
            //});
        }
        else {
            var defaultData = {};
            $('#form').setWebControls(defaultData);
        }
    }

    function saveForm(index) {
        if ($('#form').validate().form()) {
            var postData = $('#form').getWebControls({ Id: id });
            postData.moduleIds = $('#moduleTree').ysTree("getCheckedNodes");
            ys.ajax({
                url: '@Url.Content("~/QixingManage/ModuleCategoryUser/SaveFormJson")',
                type: 'post',
                data: postData,
                success: function (obj) {
                    if (obj.Tag == 1) {
                        ys.msgSuccess(obj.Message);
                        parent.searchGrid();
                        parent.layer.close(index);
                    }
                    else {
                        ys.msgError(obj.Message);
                    }
                }
            });
        }
    }
</script>

